//
//  NYIPACollectionViewCell.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/2/4.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYIPACollectionViewCell.h"
#import "NYIAPModel.h"

@interface NYIPACollectionViewCell ()

@property (nonatomic, strong) UILabel *ipaLabel;
@property (nonatomic, strong) UILabel *moneyLabel;
@property (nonatomic, strong) NYIAPModel *iapModel;

@end

@implementation NYIPACollectionViewCell

+ (CGSize)sizeForObject:(id)object identifier:(NSString *)identifier atIndexPath:(NSIndexPath *)indexPath collectionView:(UICollectionView *)collectionView {
    
    CGFloat width = (SCREEN_WIDTH - 80)/3.f;
    return CGSizeMake(width, width * 264/327);
}
- (BOOL)shouldUpdateCellWithObject:(NYIAPModel *)object {
    
    if (![object isKindOfClass:[NYIAPModel class]]) {
        return false;
    }
    
    self.ipaModel = object;
    return true;
}


#pragma mark - Intial Methods
- (void)setupView {
    [super setupView];
    
    [self setBackgroundColor:UIColorMakeWithHex(@"#E5E5E5")];
    [self.contentView setBackgroundColor:UIColorMakeWithHex(@"#E5E5E5")];
    [self.contentView addSubview:self.ipaLabel];
    [self.contentView addSubview:self.moneyLabel];
    
    [self.ipaLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(20);
        make.height.mas_equalTo(18);
    }];
    [self.moneyLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-15);
        make.height.mas_equalTo(16);
    }];
}

#pragma mark - Public Methods

#pragma mark - Private Method
- (void)updateContent {
    _ipaLabel.text = _iapModel.iap;
    _moneyLabel.text = _iapModel.money;
    
}
#pragma mark - Setter Getter Methods
- (void)setIpaModel:(NYIAPModel *)iapModel {
    _iapModel = iapModel;
    [self updateContent];
}
- (UILabel *)ipaLabel {
    if (!_ipaLabel) {
        _ipaLabel = [[UILabel alloc] init];
        _ipaLabel.font = UIFontMake(16);
        _ipaLabel.textAlignment = NSTextAlignmentCenter;
        _ipaLabel.textColor = UIColorMakeWithHex(@"#333333");
    }
    return _ipaLabel;
}
- (UILabel *)moneyLabel {
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc] init];
        _moneyLabel.font = UIFontMake(14);
        _moneyLabel.textAlignment = NSTextAlignmentCenter;
        _moneyLabel.textColor = UIColorMakeWithHex(@"#999999");
    }
    return _moneyLabel;
}
@end
